home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Apple Color OneScanner SDK / Scan Image 1.0 / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  3.8 KB  |  175 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************
  2. #
  3. #        init.c
  4. #
  5. #        basic initialization code.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            4/3/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28.  
  29. #include <AppleEvents.h>
  30. #include <Displays.h>
  31. #include <Events.h>
  32. #include <Fonts.h>
  33. #include <Gestalt.h>
  34. #include <Menus.h>
  35. #include <OSUtils.h>
  36.  
  37. #include "App.h"
  38. #include "Proto.h"
  39.  
  40.  
  41. //----------------------------------------------------------------------
  42. //    Globals
  43. //----------------------------------------------------------------------
  44.  
  45. extern Boolean             gHasDMTwo;
  46. extern Boolean             gHasDrag;
  47. extern Boolean            gInBackground;
  48. extern short            gWindCount;
  49.  
  50.  
  51. //----------------------------------------------------------------------
  52. //
  53. //    Initialize - the main entry point for the initialization
  54. //
  55. //
  56. //----------------------------------------------------------------------
  57.  
  58. OSErr Initialize(void)
  59. {
  60.     OSErr        err = noErr;
  61.     
  62.     
  63.     ToolBoxInit();
  64.     CheckEnvironment();
  65.     err = InitApp();
  66.     
  67.     return err;
  68. }
  69.  
  70.  
  71. //----------------------------------------------------------------------
  72. //
  73. //    ToolBoxInit - initialization all the needed managers
  74. //
  75. //
  76. //----------------------------------------------------------------------
  77.  
  78. void ToolBoxInit(void)
  79. {
  80.  
  81.     InitGraf(&qd.thePort);
  82.     InitFonts();
  83.     InitWindows();
  84.     InitMenus();
  85.     TEInit();
  86.     InitDialogs(nil);
  87.     InitCursor();
  88.         
  89.     FlushEvents(everyEvent, 0);
  90.  
  91. }
  92.  
  93.  
  94. //----------------------------------------------------------------------
  95. //
  96. //    CheckEnvironment - make sure we can run with current sys and managers.
  97. //                       Also initialize globals - have drag & drop
  98. //                      
  99. //----------------------------------------------------------------------
  100.  
  101. void CheckEnvironment(void)
  102. {
  103.     OSErr            err;
  104.     long            response;
  105.     
  106.  
  107.     // check to see if the Display Manager is present. If it is 
  108.     // then we have a PowerMac or System 7.5.
  109.     err = Gestalt(gestaltDisplayMgrAttr, &response);
  110.     
  111.     if (err != noErr || ((response & (1 << gestaltDisplayMgrPresent)) == 0))
  112.          HandleAlert(kNeedsDisplayManager);
  113.     
  114.     // check for Display Manager 2.0
  115.     else {
  116.         Gestalt(gestaltDisplayMgrVers, (long*)&response);
  117.         gHasDMTwo = (response >= 0x00020000);
  118.     }
  119.  
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------
  124. //
  125. //    InitApp - initialization all the application specific stuff
  126. //
  127. //
  128. //----------------------------------------------------------------------
  129.  
  130. OSErr InitApp(void)
  131. {
  132.     OSErr                err;
  133.  
  134.     // init AppleEvents
  135.     err = AEInit();
  136.     MenuSetup();
  137.  
  138.     // we have DM 2.0 so install
  139.     // world changed notification proc
  140.     if (gHasDMTwo)
  141.         err = InstallDMNotification();
  142.  
  143.     // we have DM 1.0 so install AppleEvent Notification
  144.     else
  145.         err = InstallAEDMNotification();
  146.  
  147.     // init any globals
  148.     gWindCount = 1;
  149.  
  150.     return err;                    
  151. }
  152.  
  153.  
  154. //----------------------------------------------------------------------
  155. //
  156. //    MenuSetup - 
  157. //
  158. //
  159. //----------------------------------------------------------------------
  160.  
  161. void MenuSetup(void)
  162. {
  163.     Handle            menu;
  164.         
  165.         
  166.     menu = GetNewMBar(rMBarID);        //    get our menus from resource
  167.     SetMenuBar(menu);
  168.     DisposeHandle(menu);
  169.     AddResMenu(GetMHandle(mApple ), 'DRVR');        //    add apple menu items
  170.  
  171.     DrawMenuBar();
  172.  
  173.         
  174. }
  175.